﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2012/2/20 23:31:24
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sector7.Framework.Utility
{
    /// <summary>
    /// 转换工具类
    /// </summary>
    public class ConvertUtil
    {
        #region Public functions
        /// <summary>
        /// string数组转换成int数组
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static int[] StringArrayToIntArray(string[] source)
        {
            int[] target = new int[source.Length];

            for (int i = 0; i < source.Length; ++i)
            {
                target[i] = Convert.ToInt32(source[i]);
            }

            return target;
        }

        /// <summary>
        /// string转换成byte数组
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static byte[] StringToByteArray(string source)
        {
            byte[] array = Encoding.UTF8.GetBytes(source);
            return array;
        }

        /// <summary>
        /// string转换成byte指针
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static unsafe void StringToBytePoint(string source, byte* target)
        {
            byte[] array = StringToByteArray(source);
            for (int i = 0; i < array.Length; ++i)
            {
                target[i] = array[i];
            }
        }

        public static string ValueTypeToDBType(string source) 
        {

            string target = string.Empty;
            switch(source) {
                case "S":
                    target = "nvarchar";
                    break;
                case "L":
                    target = "bit";
                    break;
                case "N":
                    target = "int";
                    break;
                case "D":
                    target = "date";
                    break;
                case "DT":
                    target = "datetime";
                    break;
                case "T":
                    target = "time";
                    break;
                case "BY":
                    target = "binary";
                    break;
                default :
                    break;
            }
            return target;
        }
        #endregion
    }
}
